<template>
  <div class="login-container">
    <h1>用户登录</h1>
    <form @submit.prevent="handleLogin">
      <div class="form-group">
        <label>用户名: </label>
        <input
          type="text"
          v-model="username"
          required
          placeholder="输入您的用户名"
        />
      </div>
      
      <div class="form-group">
        <label>密码: </label>
        <input
          type="password"
          v-model="password"
          required
          placeholder="输入您的密码"
        />
      </div>
      
      <button type="submit" class="login-btn">登录</button>
      <p v-if="errorMessage" class="error">{{ errorMessage }}</p>
    </form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: '',
      errorMessage: ''
    };
  },
  methods: {
    handleLogin() {
      // 简单的登录验证逻辑
      if (!this.username || !this.password) {
        this.errorMessage = "用户名和密码不能为空";
        return;
      }
      
      if (this.password.length < 6) {
        this.errorMessage = "密码长度不能少于6个字符";
        return;
      }
      
     // 模拟API请求延迟
      setTimeout(() => {
        // 模拟登录成功
        localStorage.setItem('isAuthenticated', 'true')
        
       this.$router.push({ name: 'Dashboard' });
      }, 500)
    }
  }
};
</script>

<style scoped>
.login-container {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
  width: 100%;
  max-width: 450px;
  padding: 40px;
  margin: 40px auto;
  position: relative;
  overflow: hidden;
  transform: translateY(0);
  transition: transform 0.3s ease;
}

.login-container:hover {
  transform: translateY(-5px);
}

.login-container::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent, rgba(106, 17, 203, 0.05), transparent);
  transform: rotate(30deg);
  z-index: 0;
}

.login-container > * {
  position: relative;
  z-index: 1;
}

h1 {
  text-align: center;
  color: #2d3748;
  margin-bottom: 30px;
  font-weight: 700;
  font-size: 28px;
  position: relative;
}

h1::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 4px;
  background: linear-gradient(to right, #6a11cb, #2575fc);
  border-radius: 2px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 25px;
}

.form-group {
  position: relative;
}

label {
  display: block;
  margin-bottom: 8px;
  color: #4a5568;
  font-weight: 600;
  font-size: 15px;
  padding-left: 5px;
}

input {
  width: 100%;
  padding: 16px 20px 16px 20px;
  border: 2px solid #e1e5ee;
  border-radius: 12px;
  font-size: 16px;
  transition: all 0.3s ease;
  background-color: #f8f9fc;
  position: relative;
}

input:focus {
  outline: none;
  border-color: #6a11cb;
  box-shadow: 0 0 0 3px rgba(106, 17, 203, 0.2);
  background-color: #fff;
}

input::placeholder {
  color: #a0aec0;
}

.login-btn {
  background: linear-gradient(to right, #6a11cb, #2575fc);
  color: white;
  border: none;
  padding: 16px;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 5px 15px rgba(106, 17, 203, 0.25);
  margin-top: 10px;
}

.login-btn:hover {
  background: linear-gradient(to right, #5a0db0, #1d68e0);
  transform: translateY(-2px);
  box-shadow: 0 7px 20px rgba(106, 17, 203, 0.35);
}

.login-btn:active {
  transform: translateY(0);
}

.error {
  text-align: center;
  color: #e53e3e;
  background: rgba(229, 62, 62, 0.1);
  padding: 12px;
  border-radius: 8px;
  font-weight: 500;
  margin-top: 10px;
  animation: shake 0.5s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* 响应式设计 */
@media (max-width: 500px) {
  .login-container {
    padding: 30px 20px;
    margin: 20px;
  }
  
  h1 {
    font-size: 24px;
  }
  
  input {
    padding: 14px 16px;
  }
}
</style>